import React, { Component } from 'react';
import { connect } from 'react-redux';
import { getRecruitList } from '../../store/action/recruitList.js';
import { timeFormat } from '../../utils/utils';
import Storage from '../../utils/utils';
import { message, Button} from 'antd';
import './AuditList.css';
import { Link } from 'react-router-dom';


@ connect(state => ({
    recruitList: state.recruitList.list
}))
class AuditList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],//招新清单数据
            listTotal: 1,//招新信息总条数
            curPage: 0,//当前页数
            isEnough: false,//招新信息是否加载完毕
            loading: false,//按钮加载效果
            isStu:Storage.getStorage('isStudent'),//是否是学生
            id:0
        }
    }
    componentWillMount() {
        this.handleGetList();
    }


    /**
     * 获取招新数据
     */
    handleGetList = () => {
        this.setState({ loading: true });
        if (this.state.curPage * 5 >= this.state.listTotal) {
            //招新信息数据已经加载完毕
            this.setState({
                isEnough: true
            })
            message.info("加载完毕");
            this.setState({ loading: false });
        }
        else {
            this.props.dispatch(getRecruitList({ page: this.state.curPage + 1, rows: 5 })).then(() => {
                //将新加载的数据加入老数据中
                let _newList = this.state.list;
                for(let i=0;i<this.props.recruitList.pagingList.length;i++)
                {
                    _newList.push(this.props.recruitList.pagingList[i]);
                }
                this.setState({
                    list: _newList,
                    listTotal: this.props.recruitList.total,
                    curPage: this.state.curPage + 1
                })
            });
            this.setState({ loading: false });
        }
    }





    outTime=(startTime,endTime)=>
    {
        let nowTime=Date.now();
        if(endTime*1000>=nowTime&&startTime*1000<=nowTime)
        {
            return false;
        }
        return true;
    }
    render() {

        return (
            <div className="recruitlist-container">
                <ul className="recruitlist-container-list">
                    {
                        this.state.list.map((item, index) => {
                            return <li key={index}>
                                <i className="iconfont li-left" style={{ fontSize: 30 }}>&#xe6c1;</i>
                                <div className="li-left li-title">{item.enrollment.title}</div>
                                <div className="li-left li-time">
                                    <div>开始时间：{timeFormat(item.enrollment.startTime)}</div>
                                    <div>结束时间：{timeFormat(item.enrollment.endTime)}</div>
                                </div>
                                <div className="li-left li-btn"><Link to={'/enroll/auditrecruit/'+item.enrollment.id}>
                                    <Button>审核</Button></Link>
                               </div>
                            </li>
                        })
                    }
                </ul>
                {
                    this.state.isEnough ? <div className="recruitlist-nomore">已经到底部了哦！</div> 
                    :<div className="more-btn">
                        <Button 
                        className="recruitlist-lookmore" 
                        type="primary" 
                        loading={this.state.loading} 
                        onClick={this.handleGetList}>
                        查看更多
                    </Button></div>
                }
            </div>
        )
    }
}
export default AuditList;